﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=1003",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab = tabs.getTab("tab$1003");
                    tabs.removeTab(tab);
                }
            }
        });

        var HideAll = [{ id: 0, text: '显示' }, { id: 1, text: '隐藏' }, { id: -1, text: '全部'}];
        var Hide = [{ id: 0, text: '显示' }, { id: 1, text: '隐藏'}];
        var HideShow = [{ id: 0, text: '<font color="#009900">显示</font>' }, { id: 1, text: '<font color="#ff3300">隐藏</font>'}];
    </script>
</head>
<body>
    <div class="mini-toolbar" style="border-bottom: 0;">
        <table>
            <tr>
                <td>
                    关键字：
                    <input class="mini-textbox" id="key" emptytext="单位名称、营业执照号或会员代表关键字" />
                    状态：
                    <input id="state" class="mini-combobox" style="width: 60px;" data="HideAll" value="0"/>
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="search();">查询</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-add" plain="true" onclick="addRow();">新增</a>
                    <a class="mini-button" iconcls="icon-remove" plain="true" onclick="delRows()">删除</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-unlock" plain="true" onclick="lockRows(0);">显示</a>
                    <a class="mini-button" iconcls="icon-lock" plain="true" onclick="lockRows(1)">隐藏</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowresize="true"
            idfield="id" multiselect="true" url="../data/system.aspx?method=GetMemberList" sizeList="[15,20,50,100]" pageSize="15">
            <div property="columns">
                <div type="checkcolumn">
                </div>
                <div cellCls="actionIcons" name="action" width="60px" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
                <div field="hr_company" headeralign="center" align="center" allowsort="true">单位名称</div>
                <div field="hr_hide" width="50px" headeralign="center" align="center" allowsort="true" renderer="onHideRenderer">状态</div>
                <div field="hr_card" width="100px" headeralign="center" align="center" allowsort="true">营业执照号</div>
                <div field="hr_type" width="100px" headeralign="center" align="center" allowsort="true">企业性质</div>
                <div field="hr_business" width="100px" headeralign="center" align="center" allowsort="true">经营范围</div>
                <div field="hr_tel" width="100px" headeralign="center" align="center" allowsort="true">联系电话</div>
                <div field="hr_name" width="100px" headeralign="center" align="center" allowsort="true">会员代表姓名</div>
                <div field="hr_job" width="100px" headeralign="center" align="center" allowsort="true">职务</div>
                <div field="hr_count" width="70px" headeralign="center" align="center" renderer="onPayRenderer">缴费</div>
            </div>
        </div>
    </div>
    <div id="editWindow" class="mini-window" title="会员信息<span class='red'>( 带 * 号的必须填写)</span>" style="width: 620px;" showmodal="true"
        allowresize="false" allowdrag="true" showFooter="true">
        <div id="editform" class="form">
            <input class="mini-hidden" name="hr_no" id="hr_no" />
            <fieldset style="border:solid 1px #aaa;padding:3px;">
                <legend >单位信息</legend>
                <table>
                    <tr style="height: 20px">
                        <td class="tdtitle" style="width: 100px;">
                            <span class="red">*</span>单位名称：
                        </td>
                        <td class="tdtext" style="width: 200px;">
                            <input name="hr_company" class="mini-textbox" required="true" style="width: 150px;" />
                        </td>
                        <td class="tdtitle" style="width: 100px;">
                            <span class="red">*</span>营业执照号：
                        </td>
                        <td class="tdtext" style="width: 200px;">
                            <input name="hr_card" class="mini-textbox" required="true" style="width: 150px;" />
                        </td>
                    </tr>
                    <tr style="height: 20px">
                        <td class="tdtitle">
                            邮政编码：
                        </td>
                        <td class="tdtext">
                            <input name="hr_postcode" class="mini-textbox" style="width: 150px;" required="false" />
                        </td>
                        <td class="tdtitle">
                            <span class="red">*</span>联系电话：
                        </td>
                        <td class="tdtext">
                            <input name="hr_tel" class="mini-textbox" style="width: 150px;" required="true" />
                        </td>
                    </tr>
                    <tr style="height: 20px">
                        <td class="tdtitle">
                            传真：
                        </td>
                        <td class="tdtext">
                            <input name="hr_fax" class="mini-textbox" style="width: 150px;" required="false" />
                        </td>
                        <td class="tdtitle">
                            单位性质：
                        </td>
                        <td class="tdtext">
                            <input name="hr_type" class="mini-textbox" style="width: 150px;" required="false" />
                        </td>
                    </tr>
                    <tr style="height: 20px">
                        <td class="tdtitle">
                            隶属关系：
                        </td>
                        <td class="tdtext">
                            <input name="hr_subject" class="mini-textbox" style="width: 150px;" required="false" />
                        </td>
                        <td class="tdtitle">
                            经营范围：
                        </td>
                        <td class="tdtext">
                            <input name="hr_business" class="mini-textbox" style="width: 150px;" required="false" />
                        </td>
                    </tr>
                    <tr style="height: 20px">
                        <td class="tdtitle">
                            <span class="red">*</span>通讯地址：
                        </td>
                        <td class="tdtext" colspan="3">
                            <input name="hr_address" class="mini-textbox" required="true" style="width: 450px;" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            单位基本情况：
                        </td>
                        <td class="tdtext" colspan="3">
                            <input name="hr_memo" class="mini-textarea" style="width: 450px; height: 60px;" />
                        </td>
                    </tr>
                </table>
            </fieldset>
            <fieldset style="border:solid 1px #aaa;padding:3px;">
                <legend >会员代表信息</legend>
                <table>
                    <tr style="height: 20px">
                        <td class="tdtitle" style="width: 80px;">
                            <span class="red">*</span>姓名：
                        </td>
                        <td class="tdtext">
                            <input name="hr_name" class="mini-textbox" required="true" style="width: 150px;" />
                        </td>
                        <td class="tdtitle" style="width: 80px;">
                            性别：
                        </td>
                        <td class="tdtext">
                            <input name="hr_sex" class="mini-combobox" repeatlayout="table" repeatdirection="vertical"
                                style="width: 100px;" url="../data/system.aspx?method=GetCbxSex" textfield="di_name"
                                valuefield="di_code" value="0" required="true" />
                        </td>
                        <td class="tdtitle" style="width: 80px;">
                            民族：
                        </td>
                        <td class="tdtext">
                            <input name="hr_nation" class="mini-textbox" required="false" style="width: 100px;" />
                        </td>
                    </tr>
                    <tr style="height: 20px">
                        <td class="tdtitle">
                            出生年月：
                        </td>
                        <td class="tdtext">
                            <input name="hr_birth" class="mini-textbox" style="width: 150px;" required="false" />
                        </td>
                        <td class="tdtitle">
                            文化程度：
                        </td>
                        <td class="tdtext">
                            <input name="hr_education" class="mini-combobox" repeatlayout="table" repeatdirection="vertical"
                                style="width: 100px;" url="../data/system.aspx?method=GetCbxEdu" textfield="di_name"
                                valuefield="di_code" value="0" required="false" />
                        </td>
                        <td class="tdtitle">
                            政治面貌：
                        </td>
                        <td class="tdtext">
                            <input name="hr_political" class="mini-textbox" style="width: 100px;" required="false" />
                        </td>
                    </tr>
                    <tr style="height: 20px">
                        <td class="tdtitle">
                            固定电话：
                        </td>
                        <td class="tdtext">
                            <input name="hr_phone" class="mini-textbox" style="width: 150px;" required="false" />
                        </td>
                        <td class="tdtitle">
                            职务：
                        </td>
                        <td class="tdtext">
                            <input name="hr_job" class="mini-textbox" style="width: 100px;" required="false" />
                        </td>
                        <td class="tdtitle">
                            职称：
                        </td>
                        <td class="tdtext">
                            <input name="hr_technical" class="mini-textbox" style="width: 100px;" required="false" />
                        </td>
                    </tr>
                    <tr style="height: 20px">
                        <td class="tdtitle">
                            手机：
                        </td>
                        <td class="tdtext">
                            <input name="hr_mobile" class="mini-textbox" style="width: 150px;" required="false" />
                        </td>
                        <td class="tdtitle">
                            QQ：
                        </td>
                        <td class="tdtext">
                            <input name="hr_qq" class="mini-textbox" style="width: 100px;" required="false" />
                        </td>
                    </tr>
                </table>
            </fieldset>
        </div>
        <div property="footer" style="text-align:center;padding:5px;">
            <a class="mini-button" style="width:60px;" onclick="updateRow()">保存</a>
            <span style="display:inline-block;width:25px;"></span>
            <a class="mini-button" style="width:60px;" onclick="closewin()">关闭</a>
        </div>
    </div>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                // 通过XMLHttpRequest取得响应头，sessionstatus
                var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });

        mini.parse();

        var grid = mini.get("datagrid1");
        search();

        function search() {
            var key = mini.get("key").getValue();
            var state = mini.get("state").getValue();
            grid.load({ key: key, state: state });
            grid.sortBy("hr_no", "asc");
        }

        //缴费显示
        function onPayRenderer(e) {
            var s = '<a class="linelink" title="详细" href="javascript:void(0);" onclick="payRows(' + e.record._uid + ')">管理</a> (' + e.value + ')';
            return s;
        }

        function addRow() {
            var form = new mini.Form("#editform");
            form.reset();
            form.loading();
            form.unmask();
            var win = mini.get("editWindow");
            win.setTitle("新增会员信息<span class='red'>( 带 * 号的必须填写)</span>");
            if (!win.visible)
                win.show();
        }

        function editRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var win = mini.get("editWindow");
                var form = new mini.Form("#editform");
                form.clear();
                form.loading();
                $.ajax({
                    url: "../data/system.aspx?method=GetMember&id=" + row.hr_no,
                    success: function (text) {
                        form.unmask();
                        if (text == "out") {
                            win.hide();
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        var o = mini.decode(text);
                        form.setData(o);
                        win.setTitle("编辑会员信息<span class='red'>( 带 * 号的必须填写)</span>");
                        win.show();
                    },
                    error: function () {
                        ShowMessage("系统提示", "表单加载出错！", 3);
                        form.unmask();
                    }
                });
            }
        }

        function updateRow() {
            var form = new mini.Form("#editform");
            form.validate();
            if (form.isValid() == false)
                return;
            var o = form.getData();
            var json = mini.encode(o);

            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });
            $.ajax({
                url: "../data/system.aspx?method=SaveMember",
                data: { data: json },
                success: function (ret) {
                    mini.unmask(document.body);
                    if (ret == "out") {
                        var loginWindow = parent.mini.get("loginWindow");
                        if (!loginWindow.visible)
                            loginWindow.show();
                        return;
                    }
                    var editWindow = mini.get("editWindow");
                    if (ret == 1) {
                        editWindow.hide();
                        ShowMessage("系统提示", "会员保存成功！", 1);
                        grid.reload();
                    }
                    else if (ret == 0) {
                        editWindow.hide();
                        ShowMessage("系统提示", "该会员已不存在，请确认！", 2);
                        grid.reload();
                    }
                    else if (ret == 2) {
                        editWindow.hide();
                        ShowMessage("系统提示", "该会员已存在，请确认！", 2);
                    }
                    else
                        ShowMessage("系统提示", "会员保存失败！", 3);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    mini.unmask(document.body);
                    ShowMessage("系统提示", "会员保存失败！", 3);
                }
            });
        }

        function delRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                mini.confirm("确定删除此会员？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            $.ajax({
                                url: "../data/system.aspx?method=DeleteMember",
                                type: "post",
                                data: { id: row.hr_no },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "会员删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "会员删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "会员删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
        }

        function delRows() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                mini.confirm("确定删除所选会员？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].hr_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=DeleteMember",
                                type: "post",
                                data: { id: ids },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "会员删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "会员删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "会员删除失败！", 3);
                                }
                            });
                        }
                    }
                );
                } 
            else
                ShowMessage("系统提示", "请选择需要删除的会员！", 2);
        }

        function lockRows(state) {
            var rows = grid.getSelecteds();
            var msg = "隐藏";
            if (state == 0)
                msg = "显示";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选会员？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].hr_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=LockMember",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "会员" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "会员" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "会员" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            } 
            else
                ShowMessage("系统提示", "请选择需要" + msg + "的会员！", 2);
        }

        function closewin() {
            var win = mini.get("editWindow");
            win.hide();
        }

        //管理缴费
        function payRows(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var tabs = parent.mini.get("mainTabs");
                var tab = tabs.getTab("tab$1003");
                tab.enabled = false;
                showRTab(row.hr_no);
            }
        }

        //打开管理缴费Tab
        function showRTab(hr_no) {
            var tabs = parent.mini.get("mainTabs");
            var id = "tab$mpay";
            var tab = tabs.getTab(id);
            if (!tab) {
                tab = {};
                tab.name = id;
                tab.title = "HR会员缴费记录管理";
                tab.showCloseButton = true;
                tab.url = "HR/payment.html?hrno=" + hr_no;
                tabs.addTab(tab);
            }
            tabs.activeTab(tab);
        }
    </script>
</body>
</html>